<template>
<div>
  <div class="slide-five">
    <div class="title">为爱表白</div>
    <div class="text">在下方区域内手写出</div>
    <div class="text">属于你最特别的"520"</div>
    <div class="text add-margin-bottom">在特别的日子里对他们表白</div>
    <canvas id="canvas" ref="canvas" style="background-color:rgb(255,255,255)">
        <p>you brower is not support canvas</p>
    </canvas>
    <div class="btns">
      <div id="savepic" @click="onBrush"  class="btn">清空</div>
      <div id="savepic" @click="oncanvasImgUrl"  class="btn">送出你的表白</div>
    </div>
  </div>
  </div>
</template>
<script>
import { drawCanvas } from '../lib/cavas.js'
export default {
  name: 'Send',
  data () {
    return {
      canvasImgUrl: '',
      eraserflag: 1,
      brushflag: 0
    }
  },
  mounted () {
    let canvas = this.$refs.canvas
    let context = canvas.getContext('2d')
    drawCanvas(context, canvas, this.eraserflag, this.brushflag)
  },
  methods: {
    onBrush () {
      let canvas = this.$refs.canvas
      let context = canvas.getContext('2d')
      this.eraserflag = 1
      this.brushflag = 0
      drawCanvas(context, canvas, this.eraserflag, this.brushflag)
    },
    onEraser () {
      this.eraserflag = 0
      this.brushflag = 1
      let canvas = this.$refs.canvas
      let context = canvas.getContext('2d')
      drawCanvas(context, canvas, this.eraserflag, this.brushflag)
    },
    oncanvasImgUrl () {
      let canvas = this.$refs.canvas
      this.canvasImgUrl = canvas.toDataURL()
      this.$router.push({path: 'success', query: {imgUrl: this.canvasImgUrl}})
    }
  }
}
</script>
<style  @scoped lang="less">
    .slide-five{
      height: 100vh;
      width: 7.5rem;
      overflow: hidden;
      background: url(http://img18.3lian.com/d/file/201704/18/fa48ed4a34f5978cb1860e684a9f2fd0.jpg);
      background-size:100%;
      text-align:center;
      top:0;
      .canvas{
        background: #FFF;
      }
      .title{
        font-size: 1rem;
        margin-top: 1.5rem;
        margin-bottom: .7rem;
        color: #000;
        font-weight: bold;
      }
      .text{
        font-size: .3rem;
        font-weight: bold;
        margin-bottom: .1rem;
        font-family: serif;
      }
      .textarea{
        width: 7.5rem;
        height: 5rem;
        margin-top: .5rem;
      }
      .btns{
        display: flex;
        font-size: .3rem;
        color: #666;
        margin-left: .3rem;
        margin-top: 1rem;
      }
      .btn{
        border: .01rem solid #666;
        border-radius: .07rem;
        text-align: center;
        padding: .2rem .2rem;
        width: 2.9rem;
        margin-right: .3rem;
      }
      .add-margin-bottom{
        margin-bottom: 1rem;
      }
    }
    </style>
